package servlets;


import entity.User;
import service.UserService;
import service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.List;

public class loginServlet extends HttpServlet {
    private UserService us=new UserServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
      resp.setContentType("text/html;charset=utf-8");
      req.setCharacterEncoding("utf-8");
       String name=req.getParameter("name");
       String psw=req.getParameter("psw");
        List<User> u=us.queryUser(name);
        PrintWriter pw=resp.getWriter();
        if(u==null){
            pw.write("用户不存在！");
        } else {
            for (User m:u) {
                if(m.getPassword().equals(psw)){
                    if(m.getStatus()==1){
                        pw.write("登录成功");
                    }else {
                        pw.write("没有权限");
                    }
                }else {
                    pw.write("密码不正确");
                }

            }
        }

    }
}
